package fr.afcepf.ai90.util;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ResourceBundle;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**
 * Connexion a la BDD.
 * 
 * @author stagiaire
 * 
 */
public class SimpleDataSource implements DataSource {

    public Connection getConnection() throws SQLException {
        Connection connection = null;

        // chargement driver jdbc pour mysql:
        try {
            ResourceBundle ressources = ResourceBundle.getBundle("db");
            // Class.forName("com.mysql.jdbc.Driver");
            Class.forName(ressources.getString("jdbcDriver"));

            // String url = "jdbc:mysql://localhost/minibank_db_ex1";
            String url = ressources.getString("url");

            // String username="root";
            String username = ressources.getString("username");

            // String mdp = "afcepf";
            String mdp = ressources.getString("password");

            connection = DriverManager.getConnection(url, username, mdp);
            System.out.println("connection jdbc etablie");

        } catch (Exception e) {

            e.printStackTrace();
        }
        return connection;
    }

    public PrintWriter getLogWriter() throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    public int getLoginTimeout() throws SQLException {
        // TODO Auto-generated method stub
        return 0;
    }

    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        // TODO Auto-generated method stub
        return null;
    }

    public void setLogWriter(PrintWriter arg0) throws SQLException {
        // TODO Auto-generated method stub

    }

    public void setLoginTimeout(int arg0) throws SQLException {
        // TODO Auto-generated method stub

    }

    public boolean isWrapperFor(Class<?> arg0) throws SQLException {
        // TODO Auto-generated method stub
        return false;
    }

    public <T> T unwrap(Class<T> arg0) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    public Connection getConnection(String arg0, String arg1)
            throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

}
